package io.renren.modules.app.service.impl;

import com.zheok.testing.entity.CaseEntity;
import com.zheok.testing.entity.JournalismEntity;
import com.zheok.testing.entity.ProductEntity;
import com.zheok.testing.entity.ShopEntity;
import io.renren.modules.app.service.JournalismService;
import io.renren.modules.app.service.ShopService;
import io.renren.modules.sys.entity.SysUserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.*;

import com.zheok.testing.dao.JournalismDao;
import org.springframework.util.StringUtils;


@Service("journalismService")
public class JournalismServiceImpl extends ServiceImpl<JournalismDao, JournalismEntity> implements JournalismService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        QueryWrapper<JournalismEntity> wrapper = new QueryWrapper<>();

        SysUserEntity userEntity = ShiroUtils.getUserEntity();
        String username = userEntity.getUsername();
        if(!"admin".equals(username)){
            wrapper.lambda().eq(JournalismEntity::getShopId,userEntity.getUserId());
        }
        String key = (String) params.get("key");

        if(!StringUtils.isEmpty(key)){
            wrapper.lambda().like(JournalismEntity::getTitle,key);
        }
        IPage<JournalismEntity> page = this.page(
                new Query<JournalismEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Autowired
    private ShopService shopService;

    @Override
    public void saveinfo(JournalismEntity journalism) {

        SysUserEntity userEntity = ShiroUtils.getUserEntity();
        journalism.setShopId(userEntity.getUserId());
        journalism.setShopName(userEntity.getName());
        this.saveOrUpdate(journalism);
    }

}